/**
 * 向外暴露核心模块
 */

import "./Style/index.less";
import { Draw } from "./Draw/Draw";
import { Command } from "./Command/Command";
import { KeyMap } from "./Enumerate/KeyMap";
import { Register } from "./Register/Register";
import { ShortCut } from "./Shortcut/ShortCut";
import { IPptxOptions } from "./Interface/Pptx";
import { EventBus } from "./Event/eventbus/EventBus";
import { PreviewMode } from "./Enumerate/PreviewMode";
import { EventBusMap } from "./Interface/EventBusMap";
import { IYjsWebsocket } from "./Interface/Websocket";
import { ShapeAnimationEnum } from "./Enumerate/ShapeAnimation";
import { SlideAnimationEnum } from "./Enumerate/SlideAnimation";

class UniPPTX {
  public command: Command;
  public register: Register;
  public render: () => void;
  public destroy: () => void;
  public eventBus: EventBus<EventBusMap>;

  constructor(options: IPptxOptions) {
    // 创建 eventbus
    this.eventBus = new EventBus<EventBusMap>();

    // 创建 draw
    const draw = new Draw({ ...options, eventbus: this.eventBus });

    // 创建 command
    this.command = draw.getCommand();

    // 创建快捷键
    const shortcut = new ShortCut(draw);

    // 提供用户注册快捷键方法
    this.register = new Register({ shortcut });

    // 提供全局强制刷新方法 - 不记录历史操作
    this.render = () => draw.render({ patchHistory: false });

    // 提供 destroy 方法
    this.destroy = () => {
      shortcut.removeEvent();
      draw.destroy();
    };
  }
}

// 提供全局变量
Reflect.set(window, "UniPPTX", UniPPTX);

export {
  UniPPTX,
  KeyMap,
  ShapeAnimationEnum,
  SlideAnimationEnum,
  PreviewMode,
  type IPptxOptions,
  type IYjsWebsocket,
};
